      Program fakul
CC
CC    Fakultaetsprogram, FORTRAN 90 Version
CC
      integer max
      integer feld(:), carry(:)
      integer I,K,N
      integer length
      integer s, lastval

      print *, 'Input value N !'
      read *, N
      print *, 'Input upper limit for size !'
      read *, max

      allocate (feld(1:max), carry(1:max))

      feld = 0
      carry = 0

      feld(1)=1
      length = 1

      do K=N,1,-1
        feld (1:length) = (feld(1:length) + carry(1:length)) * K
        carry (1:length) = feld(1:length) / 65536
        feld (1:length) = feld(1:length) - carry(1:length) * 65536
        if (carry(length) .NE. 0) length = length + 1
        carry = cshift (carry,1,-1)
      end do
     
      lastval = feld(length)
      s = sum (feld (1:length))

      deallocate (carry, feld)

      print *, 'Size        = ', length
      print *, 'Lastval     = ', lastval
      print *, 'Control sum = ', s
      end

